package com.joysuch.wwyt.patrol.controller;


import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.patrol.service.PatrolRecordItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author heqifeng
 * @since 2022-03-03
 */
@RestController
@RequestMapping("/patrol/patrol-record-item")
@Api(tags = "智能巡检-项目记录")
public class PatrolRecordItemController {
    @Autowired
    private PatrolRecordItemService recordItemService;

    @GetMapping("repair")
    @ApiOperation("处理异常")
    public ResultBean repair(Long id) {
        recordItemService.repair(id);
        return null;
    }


    @GetMapping("web-ex-item-list")
    @ApiOperation("web异常处理列表页")
    @RequiresPermissions("patrol:except:handle")
    public ResultBean getExItemByTask(Long taskId) {
        return ResultBean.success(recordItemService.getExceptItemByTask(taskId));
    }

    @GetMapping("app-ex-item-list")
    @ApiOperation("app异常处理列表页")
    public ResultBean getExItemByRecord(Long recordId) {
        return ResultBean.success(recordItemService.getExceptItemByRecord(recordId));
    }

    @PostMapping("/repairNewWf/{itemId}/{wfProcessInsId}/{wfProcessStatus}")
    @ApiOperation(value = "异常处理-新版流程引擎")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId", value = "排查记录itemID", required = true),
            @ApiImplicitParam(name = "wfProcessInsId", value = "新版流程实例id", required = true),
            @ApiImplicitParam(name = "wfProcessStatus", value = "流程状态", required = true)
    })
    @ResponseBody
    public ResultBean repairNewWf(@PathVariable Long itemId, @PathVariable String wfProcessInsId, @PathVariable String wfProcessStatus) {
        recordItemService.repairNewWf(itemId, wfProcessInsId, wfProcessStatus);
        return ResultBean.defaultSuccessResult();
    }

    /**
     *  更改状态
     * @param id
     * @param state
     * @return
     */
    @PostMapping("/updatePatrol")
    @ResponseBody
    @ApiOperation("更改状态")
    public ResultBean updatePatrol(Long id,String state){
        recordItemService.updatePatrol(id,state);
        return ResultBean.defaultSuccessResult();
    }
}

